package com.system.Controller;

import com.common.Entity.Result;
import com.github.pagehelper.PageInfo;
import com.system.Entity.Role;
import com.system.Entity.User;
import com.system.Service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/getRoleList")
    public Result getRoleList(@RequestParam Integer pageNum,
                              @RequestParam Integer pageSize,
                              @RequestParam(required = false) String roleName) {
        PageInfo<Role> pageInfo = roleService.getRoleList(pageNum, pageSize, roleName);
        return Result.success(pageInfo);
    }
    @GetMapping("/getRoleLists")
    public Result getRoleLists() {
        List<Role> list = roleService.getRoleLists();
        return Result.success(list);
    }

    @PostMapping("/addRole")
    public Result addRole(@RequestBody Role role) {
        roleService.addRole(role);
        return Result.success();
    }

    @PutMapping("/updateRole")
    public Result updateRole(@RequestBody Role role) {
        roleService.updateRole(role);
        return Result.success();
    }

    @DeleteMapping("/deleteRole/{roleId}")
    public Result deleteRole(@PathVariable("roleId") String roleId) {
        roleService.deleteRole(roleId);
        return Result.success();
    }



}
